<template>
  <header class="navbar">
    <div class="container">
      <!-- 添加仓库按钮 -->
      <a href="https://gitee.com/li-3179/film.git" target="_blank" rel="noopener noreferrer" class="repo-btn">
        <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" class="gitee-icon">
          <path d="M512 1024C229.222 1024 0 794.778 0 512S229.222 0 512 0s512 229.222 512 512-229.222 512-512 512zm259.149-568.883h-290.74a25.293 25.293 0 0 0-25.292 25.293l-0.026 63.206c0 13.952 11.315 25.293 25.267 25.293h177.024c13.978 0 25.293 11.315 25.293 25.267v12.646a75.853 75.853 0 0 1-75.853 75.853h-240.23a25.293 25.293 0 0 1-25.267-25.293V417.203a75.853 75.853 0 0 1 75.827-75.853h353.946a25.293 25.293 0 0 0 25.267-25.292l0.077-63.207a25.293 25.293 0 0 0-25.268-25.293H417.152a189.62 189.62 0 0 0-189.62 189.645V771.15c0 13.977 11.316 25.293 25.294 25.293h372.94a170.65 170.65 0 0 0 170.65-170.65V480.384a25.293 25.293 0 0 0-25.293-25.267z" fill="#C71D23"/>
        </svg>
      </a>
      
      <router-link to="/" class="logo">
        <span class="logo-icon">🎬</span>
        <span class="logo-text">电商天堂</span>
      </router-link>
      
      <div class="nav-links">
        <router-link to="/movies">电商列表</router-link>
        <router-link v-if="userStore.isLoggedIn" to="/movies/create">添加电商</router-link>
      </div>
      
      <div class="auth-buttons">
        <template v-if="!userStore.isLoggedIn">
          <router-link to="/login" class="login-btn">登录</router-link>
          <router-link to="/register" class="register-btn">注册</router-link>
        </template>
        <template v-else>
          <el-dropdown>
            <span class="user-avatar">
              {{ userStore.user.username }}<el-icon><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </template>
      </div>
    </div>
  </header>
</template>

<script>
import { useUserStore } from '../stores/user'
import { ArrowDown } from '@element-plus/icons-vue'

export default {
  components: { ArrowDown },
  setup() {
    const userStore = useUserStore()
    
    const logout = () => {
      userStore.logout()
      window.location.href = '/'
    }
    
    return { userStore, logout }
  }
}
</script>

<style scoped>
.navbar {
  background-color: var(--dark-bg);
  color: white;
  padding: 15px 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

/* 新增的仓库按钮样式 */
.repo-btn {
  margin-right: 15px;
  display: flex;
  align-items: center;
  transition: transform 0.3s;
}

.gitee-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.repo-btn:hover {
  transform: scale(1.1);
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: white;
  font-weight: bold;
  font-size: 1.5rem;
}

.logo-icon {
  margin-right: 10px;
  font-size: 1.8rem;
}

.nav-links {
  display: flex;
  gap: 20px;
}

.nav-links a {
  color: white;
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.nav-links a:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.nav-links a.router-link-exact-active {
  background-color: var(--primary-color);
}

.auth-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.login-btn, .register-btn {
  padding: 8px 15px;
  border-radius: 4px;
  text-decoration: none;
  transition: all 0.3s;
}

.login-btn {
  color: white;
  border: 1px solid white;
}

.login-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.register-btn {
  background-color: var(--primary-color);
  color: white;
}

.register-btn:hover {
  opacity: 0.9;
}

.user-avatar {
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

@media (max-width: 768px) {
  .container {
    flex-direction: column;
    gap: 15px;
  }
  
  .nav-links {
    order: 3;
    width: 100%;
    justify-content: center;
  }
  
  /* 移动端调整仓库按钮位置 */
  .repo-btn {
    position: absolute;
    left: 15px;
    top: 15px;
  }
  
  .logo {
    margin-left: 30px; /* 为仓库按钮留出空间 */
  }
}
</style>